package com.meituan.catering.management.order.biz.model.converter;

import com.meituan.catering.management.order.api.http.model.request.PrepareCateringOrderHttpRequest;
import com.meituan.catering.management.order.biz.model.request.PrepareCateringOrderBizRequest;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Believe
 * Date 2022/5/31 14:26
 */
public class PrepareCateringOrderBizRequestConverter {
    public static PrepareCateringOrderBizRequest toPrepareCateringOrderBizRequest(PrepareCateringOrderHttpRequest request){
        if (request == null){
            return null;
        }
        PrepareCateringOrderBizRequest prepareCateringOrderBizRequest = new PrepareCateringOrderBizRequest();
        prepareCateringOrderBizRequest.setVersion(request.getVersion());
        prepareCateringOrderBizRequest.setItems(toItem(request.getItems()));
        return prepareCateringOrderBizRequest;
    }

    private static List<PrepareCateringOrderBizRequest.Item> toItem(List<PrepareCateringOrderHttpRequest.Item> itemList){
        List<PrepareCateringOrderBizRequest.Item> items = new LinkedList<>();
        for (PrepareCateringOrderHttpRequest.Item item : itemList) {
            PrepareCateringOrderBizRequest.Item bizItem = new PrepareCateringOrderBizRequest.Item();
            bizItem.setSeqNo(item.getSeqNo());
            bizItem.setVersion(item.getVersion());
            items.add(bizItem);
        }
        return items;
    }
}
